from rest_framework import serializers

from goods.models import SPUSpecification, SPU


class SpecSerializer(serializers.ModelSerializer):
    """
        商品规格序列化器
    """
    spu = serializers.StringRelatedField(read_only=True)
    spu_id = serializers.IntegerField()
    class Meta:
        model = SPUSpecification
        fields = ('id', 'name', 'spu', 'spu_id')

    # spu = serializers.StringRelatedField(read_only=True)
    # spu_id = serializers.IntegerField()
    #
    # class Meta:
    #     model = SpecificationOption
    #     fields = ('id', 'value', 'spu_id', 'spu')

class SPUSerializer(serializers.ModelSerializer):
    """
        商品表序列化器
    """
    class Meta:
        model = SPU
        fields = ('id', 'name')